package com.infore.exchange.main.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.infore.common.base.EppPage;
import com.infore.common.base.Msg;
import com.infore.common.base.ResultUtil;
import com.infore.common.base.WrapperHelp;
import com.infore.common.fw.BaseController;
import com.infore.common.model.entity.exchange.TTransformInfo;
import com.infore.common.model.entity.vo.exchange.TTransformInfoVo;
import com.infore.common.request.addupdate.exchange.TTransformInfoSaveRequest;
import com.infore.common.request.query.exchange.TTransformInfoRequest;
import com.infore.common.response.ApiEntityResponse;
import com.infore.common.response.ApiListResponse;
import com.infore.common.response.ApiPageResponse;
import com.infore.common.response.ApiResponse;
import com.infore.exchange.main.service.TTransformInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * <p>
 * 数据交换 前端控制器
 * </p>
 *
 * @author lijh
 * @since 2023-02-10
 */
@RestController
@Api(value = "数据交换前端控制器", tags = "数据交换前端控制器")
@RequestMapping("/tTransformInfo")
public class TTransformInfoController extends BaseController {
	private String prefix = "/tTransformInfo";

	@Autowired
	private TTransformInfoService TTransformInfoService;

	@GetMapping()
	public String TTransformInfoController(){
		return prefix;
	}

	/**
	 * 查询数据交换列表
	 * @param ttransforminfoVo 数据交换的vo类
	 * @return Msg<Object> 结果集
	 * @author lijh
	 * @since 2023-02-10
	 */
	@PostMapping("/list")
	@ResponseBody
	@ApiOperation(value = "查询数据交换列表", notes = "数据交换列表查询 ")
	public Msg<Object> list(TTransformInfoVo ttransforminfoVo){
		//sql查询条件
		Wrapper<TTransformInfo> wrapper = null ;
		try {
			wrapper = (Wrapper<TTransformInfo>) WrapperHelp.addCondition(new EntityWrapper<TTransformInfo>(), ttransforminfoVo);
		} catch (Exception e) {
			e.printStackTrace();
			return ResultUtil.error(500,e.getMessage());
		}
		//查询方法
		Page<TTransformInfo> eppPage = new EppPage<TTransformInfo>(TTransformInfoService,ttransforminfoVo,wrapper);
		return ResultUtil.successPage(TTransformInfoService.selectPage(eppPage, wrapper));
	}

	/**
	 * 查询数据交换列表
	 * @param request 数据交换
	 * @return Msg<Object> 结果集
	 * @author lijh
	 * @since 2023-02-10
	 */
	@ResponseBody
	@ApiOperation(value = "添加数据交换", notes = "数据交换新增")
	@RequestMapping(value="/add",method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
	public ApiResponse add(@RequestBody TTransformInfoSaveRequest request){
		Wrapper<TTransformInfo> wrapper = new  EntityWrapper<TTransformInfo>();
	    wrapper.eq("transform_name", request.getTransformInfo().getTransformName());
		List<TTransformInfo> entityList = TTransformInfoService.selectList(wrapper);
		if(entityList.size()>0) {
			return ApiEntityResponse.error("500","数据交换名称已存在");
		}
		return TTransformInfoService.saveTransform(request);
	}


	/**
	 * 删除数据交换
	 *
	 * @param  transformInfoId
	 * @return Msg<Object>
	 * @author lijh
	 * @since 2023-02-10
	 */
	@RequestMapping(value = "/del", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "删除数据交换", notes = "删除数据交换")
	public ApiResponse del(String transformInfoId) {
		return TTransformInfoService.delTransform(transformInfoId);
	}



	/**
	* @Deacription 数据交换列表详情
	* @MethodName queryTransformInfo
	* @param request
	* @return {@link ApiPageResponse}
	* @Author lijianhua
	* @Date 2023/2/21 10:35
	**/
	@RequestMapping(value = "/query", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "数据交换列表详情", notes = "数据交换列表详情")
	public ApiPageResponse queryTransformInfo(@ModelAttribute TTransformInfoRequest request) {
		startPage(request);
		return TTransformInfoService.queryTransformInfo(request,page.get());
	}


	/**
	* @Deacription
	* @MethodName queryTransformInfo
	* @param
	* @return {@link ApiEntityResponse}
	* @Author lijianhua
	* @Date 2023/3/2 14:50
	**/
	@RequestMapping(value = "/jobAndTaskStatistical", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "作业与任务统计", notes = "作业与任务统计")
	public ApiEntityResponse queryTransformInfo() {
		return TTransformInfoService.queryJobAndTaskStatistical();
	}

	@RequestMapping(value = "/queryColumnsTypes", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ResponseBody
	@ApiOperation(value = "接口同步数据类型", notes = "接口同步数据类型")
	public ApiListResponse queryColumnsTypes() {

		List<Map<String,String>> list = new ArrayList<>();
		HashMap<String, String> varcharType = new HashMap<>();
		varcharType.put("key","varchar");
		varcharType.put("label","字符串");
		HashMap<String, String> integerType = new HashMap<>();
		integerType.put("key","integer");
		integerType.put("label","整型");
		HashMap<String, String> floatType = new HashMap<>();
		floatType.put("key","float");
		floatType.put("label","浮点型");
		HashMap<String, String> dateType = new HashMap<>();
		dateType.put("key","date");
		dateType.put("label","日期");
		list.add(varcharType);
		list.add(integerType);
		list.add(floatType);
		list.add(dateType);
		return ApiListResponse.ok(list);
	}

}
